package com.clothing.customization.service.impl;

import com.clothing.customization.entity.ClothingAccessory;
import com.clothing.customization.entity.ClothingMaterial;
import com.clothing.customization.entity.ClothingStyle;
import com.clothing.customization.repository.ClothingAccessoryRepository;
import com.clothing.customization.repository.ClothingMaterialRepository;
import com.clothing.customization.repository.ClothingStyleRepository;
import com.clothing.customization.service.ClothingService;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 服装相关服务实现类
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ClothingServiceImpl implements ClothingService {
    
    private final ClothingStyleRepository clothingStyleRepository;
    private final ClothingMaterialRepository clothingMaterialRepository;
    private final ClothingAccessoryRepository clothingAccessoryRepository;
    
    @Override
    public List<ClothingStyle> getStyles(Map<String, Object> params) {
        // TODO: 根据查询参数进行过滤
        // 这里简单实现，返回所有启用的款式
        return clothingStyleRepository.findByStatusOrderByCreateTimeDesc(1);
    }
    
    @Override
    public List<ClothingMaterial> getMaterials(Map<String, Object> params) {
        // TODO: 根据查询参数进行过滤
        // 这里简单实现，返回所有启用的材质
        return clothingMaterialRepository.findByStatusOrderByCreateTimeDesc(1);
    }
    
    @Override
    public List<ClothingAccessory> getAccessories(Map<String, Object> params) {
        // TODO: 根据查询参数进行过滤
        // 这里简单实现，返回所有启用的配饰
        return clothingAccessoryRepository.findByStatusOrderByCreateTimeDesc(1);
    }
    
    @Override
    public ClothingStyle getStyleById(Long id) {
        return clothingStyleRepository.findById(id)
                .orElseThrow(() -> new EntityNotFoundException("服装款式不存在: " + id));
    }
    
    @Override
    public ClothingMaterial getMaterialById(Long id) {
        return clothingMaterialRepository.findById(id)
                .orElseThrow(() -> new EntityNotFoundException("服装材质不存在: " + id));
    }
    
    @Override
    public ClothingAccessory getAccessoryById(Long id) {
        return clothingAccessoryRepository.findById(id)
                .orElseThrow(() -> new EntityNotFoundException("服装配饰不存在: " + id));
    }
} 